<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2018/3/26
 * Time: 19:02
 */

class SimpleClass {
	// property declaration
	public $var = 'a default value';

	// method declaration
	public function displayVar() {
		echo $this->var;
	}
}

$instance = new SimpleClass();

$assigned  = $instance;
$reference =& $instance;

$instance->var = '$assigned will have this value';

$instance = null; // $instance and $reference become null
var_dump( $instance );//null
var_dump( $reference );//null
var_dump( $assigned );

///////////////////////////////////////////////////////////////////////////////
class Test {
	static public function getNew() {
		return new static;
	}
}

class Child extends Test {
}

$obj  = new Test();
$obj2 = new $obj;
$obj3 = $obj2;
echo ( $obj == $obj2 ) . PHP_EOL;//1
echo ( $obj2 == $obj3 ) . PHP_EOL;//1
$obj4 = Test::getNew();
echo ( $obj4 instanceof Test ) . PHP_EOL;//1
$obj5 = Child::getNew();
echo ( $obj5 instanceof Test ) . PHP_EOL;//1
echo ( $obj5 instanceof Child ) . PHP_EOL;//1

//////////////////////////////////////////////////////////////////////////////////////
class ExtendClass extends SimpleClass {
	// Redefine the parent method
	function displayVar() {
		echo "Extending class\n";
		parent::displayVar();
	}
}

$extended = new ExtendClass();
//Extending class
//a default value
$extended->displayVar();
